//
//  ZZFArticleDetailCell.m
//  YYUDemo
//
//  Created by zsp on 2017/3/17.
//  Copyright © 2017年 zsp. All rights reserved.
//

#import "ZZFArticleDetailCell.h"
#import <Masonry.h>

#import "ZZFConfigSet.h"
#import "UIColor+ZZFExtend.h"

@interface ZZFArticleDetailCell ()

@property(nonatomic, strong)UILabel *articleDetailLabel;

@end

@implementation ZZFArticleDetailCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self configView];
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)updateData:(id)data atIndexPath:(NSIndexPath*)indexPath {
    if (data) {
        
    }else{
        self.articleDetailLabel.attributedText=[ZZFArticleDetailCell createAttributedStrForStr:@"每次点击设置了一种歌曲循环模式，都将该循环模式发送给服务器，下次来到该界面的时候，从服务器读取数据，自动载入正确的模式，而不一定就是“顺序播放”循环模式"];
    }
    
}

- (void)configView {
    self.articleDetailLabel=[UILabel new];
    UIView *supView=self.contentView;
    [supView addSubview:self.articleDetailLabel];
    
    [self.articleDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(supView).insets(UIEdgeInsetsMake(15, 15, 15, 15));
    }];
    
    [self updateData:nil atIndexPath:nil];
}

+ (CGFloat)heightForStr:(NSString*)str whenItenWidth:(CGFloat)itemWidth {
    if (itemWidth<1) {
        itemWidth=CGRectGetWidth([UIScreen mainScreen].bounds)-30;
    }
    NSAttributedString *attributedText=[ZZFArticleDetailCell createAttributedStrForStr:str];
    CGFloat tmpHeight = [attributedText boundingRectWithSize:CGSizeMake(itemWidth-30, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size.height;
    return tmpHeight;
}

+ (NSAttributedString*)createAttributedStrForStr:(NSString*)str {
    if (str.length>0) {
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineHeightMultiple = 1.5;// 字体的行间距
        //设置字体颜色和大小
        NSDictionary *dictAttr_5 = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize_12],
                                     NSForegroundColorAttributeName:colorHex_detail_gray_3,
                                     NSParagraphStyleAttributeName:paragraphStyle
                                     };
        return [[NSAttributedString alloc] initWithString:str attributes:dictAttr_5];
    }
    
    return nil;
    
}

@end
